var  teus="0";
var ctx7_labels=[];
var ctx7_data=[];
var ctx7_labels1=[];
var ctx7_data1=[];
var labels1=[];
var datas=[];
var labels6=[];
var datas6=[];
var labels2=[];
var	datas2=[];
var datas22=[];
var labels4=[];
var datas4=[];
var total=0;
var four=0;
var total1=0;
var four1=0;
var len="";
var parameter= {"startTime":"2017-01-01"};
var geoCoordMap = {};
var  portdata=[];
$(function(){
	//地图
	mapList();
	//客户订舱量前十名
	customerTopTen();
	//七日总订舱量
    foreignBookingQuantity();
    //货物比重(全国)
    goodsCNSpecificWeight();
    //货物比重(办事处)
    goodsOrgSpecificWeight();
	//吞吐量港口排名
	throughputPortRanking();
	//航线贡献值
	routeContribution();
	//月份货物重量
	foreignMonthBookingQuantity();
	//外贸总订舱量
	foreignBookingQuantityAll();
	//箱量指标达标率
	boxTargetComplianceRate();
	//应收达标率
 	 standardReceivableRate ();

})
//应收达标率
var standardReceivableRate  =function(){
	$.ajax({
        type: "post",
        async: true,
        url: "/enReport/standardReceivableRate",
        data: {"year":2017},
        dataType: "json",
        success: function(data){
        	var datavalue ="";
        	for(var i=0; i<data.length;i++){
        		datavalue=data[0].totalpercent;
        		i=data.length;
        	}
        	var data1 =datavalue.substring(0,datavalue.length-1);
       		var gauge_2 = echarts.init(document.getElementById("gauge_2"));
			option_gauge_2 = {
			    tooltip: {
			    	show : false
			    },
			    series: [
			        {
			            name: '完成率',
			            type: 'gauge',
			            radius:'100%',
			            startAngle:180,
			            axisLine:{
			            	lineStyle:{
			            		width:10,
			            		color:[[0.2,'#0193cb'], [0.8,'#2fc5ff'], [1,'#92e1ff']],
			            	},
			            },
			            splitLine:{
			            	length:5,
			            },
			            axisTick:{
			            	show:false,
			            	length:'5%',
			            },
			            title : {
			                show : false,
			                offsetCenter: ['-65%', '30%'],
			                textStyle: {
			                    color: '#ccc',
			                    fontSize : 15
			                }
			            },
			            detail: {
			            	color: '#ccc',
			            	fontSize:22,
			            	formatter:'{value}%',
			            	offsetCenter:['-50%', '60%'],
			            },
			            data: [{value: data1, name: '箱量指标达标率'}]
			        }
			    ]
			};
			 gauge_2.setOption(option_gauge_2, true);
			setInterval(function () {
				$.ajax({
			        type: "post",
			        async: true,
			        url: "/enReport/standardReceivableRate",
			        data: {"year":2017},
			        dataType: "json",
			        success: function(data){
			        	var datavalue1 ="";
			        	for(var i=0; i<data.length;i++){
			        		datavalue1=data[0].totalpercent;
			        		i=data.length;
			        	}
			        	var data2 =datavalue1.substring(0,datavalue1.length-1);
			        	option_gauge_2.series[0].data[0].value = data2;
			   			 gauge_2.setOption(option_gauge_2, true);
					}
				})
				},3000);
					}
				})
}
//箱量指标达标率
var boxTargetComplianceRate  =function(){
	$.ajax({
        type: "post",
        async: true,
        url: "/enReport/boxTargetComplianceRate",
        data: {"year":2017},
        dataType: "json",
        success: function(data){
        	var datavalue ="";
        	for(var i=0; i<data.length;i++){
        		datavalue=data[0].totalpercent;
        		i=data.length;
        	}
        	var data1 =datavalue.substring(0,datavalue.length-1);
       		var gauge_1 = echarts.init(document.getElementById("gauge_1"));
			option_gauge_1 = {
			    tooltip: {
			    	show : false
			    },
			    series: [
			        {
			            name: '完成率',
			            type: 'gauge',
			            radius:'100%',
			            startAngle:180,
			            axisLine:{
			            	lineStyle:{
			            		width:10,
			            		color:[[0.2,'#0193cb'], [0.8,'#2fc5ff'], [1,'#92e1ff']],
			            	},
			            },
			            splitLine:{
			            	length:5,
			            },
			            axisTick:{
			            	show:false,
			            	length:'5%',
			            },
			            title : {
			                show : false,
			                offsetCenter: ['-65%', '30%'],
			                textStyle: {
			                    color: '#ccc',
			                    fontSize : 15
			                }
			            },
			            detail: {
			            	color: '#ccc',
			            	fontSize:22,
			            	formatter:'{value}%',
			            	offsetCenter:['-50%', '60%'],
			            },
			            data: [{value: data1, name: '箱量指标达标率'}]
			        }
			    ]
			};
			 gauge_1.setOption(option_gauge_1, true);
			setInterval(function () {
				$.ajax({
			        type: "post",
			        async: true,
			        url: "/enReport/boxTargetComplianceRate",
			        data: {"year":2017},
			        dataType: "json",
			        success: function(data){
			        	var datavalue1 ="";
			        	for(var i=0; i<data.length;i++){
			        		datavalue1=data[0].totalpercent;
			        		i=data.length;
			        	}
			        	var data2 =datavalue1.substring(0,datavalue1.length-1);
			        	option_gauge_1.series[0].data[0].value = data2;
			   			 gauge_1.setOption(option_gauge_1, true);
					}
				})
				},3000);
					}
				})
}
//地图
var mapList =function(){
	$.ajax({
        type: "post",
        async: true,
        url: "/enReport/portLngAndLat",
        data: parameter,
        dataType: "json",
        success: function(data){
        	 var portname="";
        	 var jwd=[];
        	 var CoordMap={};
        	 for(var i=0;i<data.length;i++){
        	 	jwd=[];
        	 	portname=data[i].portname;
        	 	jwd.push(data[i].jingdu,data[i].weidu)
        	 	CoordMap[portname]=jwd;
        	 	 
        	 }
        	 //赋值地图城市名字和经纬度
        	geoCoordMap=CoordMap;
        	//请求航线
    		$.ajax({
		        type: "post",
		        async: true,
		        url: "/enReport/routeLine",
		        data: parameter,
		        dataType: "json",
		        success: function(data){
		        	var pointdatas=[];
		        	for(var j=0;j<data.length;j++){
		        		portdata.push([{
		        			name:data[j].portname
		        		},{
		        			name:data[j].nextport,
		        			value:95
		        		}]);
		        		 pointdatas.push({
        	 				name:data[j].portname,
        	 				value:200
        	 			})
		        	}
		    $('#mainMap').height($('#mainMap').width()/1.25);
			Chart.defaults.global.defaultFontColor = '#fff';
			var main_map = echarts.init(document.getElementById("mainMap"));
			//	var geoCoordMaps= {
			//	    '上海': [121.4648,31.2891],
			//	    '东莞': [113.8953,22.901],
			// 
			//	};
			 
			var BJData =  portdata;
			var pointdata =  pointdatas;
	
			var convertData2 = function (data) {
			    var res = [];
			    for (var i = 0; i < data.length; i++) {
			        var geoCoord = geoCoordMap[data[i].name];
			        if (geoCoord) {
			            res.push({
			                name: data[i].name,
			                value: geoCoord.concat(data[i].value)
			            });
			        }
			    }
			    return res;
			};
	
			var convertData = function (data) {
			    var res = [];
			    for (var i = 0; i < data.length; i++) {
			        var dataItem = data[i];
			        var fromCoord = geoCoordMap[dataItem[0].name];
			        var toCoord = geoCoordMap[dataItem[1].name];
			        if (fromCoord && toCoord) {
			            res.push({
			                fromName: dataItem[0].name,
			                toName: dataItem[1].name,
			                coords: [fromCoord, toCoord]
			            });
			        }
			    }
			    return res;
			};
	option1 = {
	    backgroundColor: 'rgba(0,0,0,.3)',
	    title : {
	    	show:false,
	        left: 'center',
	        textStyle : {
	            color: '#fff'
	        }
	    },
	    tooltip : {
	        trigger: 'item'
	    },
 
	    visualMap: {
	        min: 0,
	        max: 200,
	        calculable: true,
	        inRange: {
	            color: ['#1966c6','#5e97c8','#d4e4f9'],
	        },
	        textStyle: {
	            color: '#fff'
	        }
	    },
	    geo: {
	        map: 'world',
	        geoIndex: 0,
	        roam:true,
	        zoom:6,
	        center: [119.97, 15.71],
	        label: {
	            emphasis: {
	                show: false
	            }
	        },
	        roam: true,
	        itemStyle: {
	            normal: {
	                areaColor: 'rgba(14, 60, 93,.8)',
	                borderColor: '#aaa',
	                borderWidth:1,
	            },
	            emphasis: {
	                areaColor: '#2a333d'
	            }
	        }
	    },
	    series: [
		    {
//		    	移动亮点
		        name: '',
		        type: 'lines',
		        zlevel: 1,
		        effect: {
		            show: true,
		            period: 6,
		            constantSpeed:30,
		            trailLength: 0.7,
		            color: '#fff',
		            symbolSize: 1
		        },
		        lineStyle: {
		            normal: {
		                color: '#fff',
		                width: 0,
		                curveness: 0.3
		            }
		        },
		        data: convertData(BJData)
		    },	
		    {	
		    	//线
		        name: '',
		        type: 'lines',
		        zlevel: 2,
		        symbol: ['none', 'arrow'],
		        symbolSize: 10,
		        effect: {
		            show: false,
		            period: 6,
		            trailLength: 0,
//		            symbol: planePath,
		            symbolSize: 1
		        },
		        lineStyle: {
		            normal: {
		                color: '#fff',
		                width: 1,
		                opacity: 0.6,
		                curveness: 0.3
		            }
		        },
		        data: convertData(BJData)
		    },
		    {
//		    	点
		        name: '',
		        type: 'effectScatter',
		        coordinateSystem: 'geo',
		        zlevel: 2,
		        rippleEffect: {
		            brushType: 'stroke'
		        },
		        label: {
		            normal: {
		                show: true,
		                position: 'right',
		                formatter: '{b}'
		            }
		        },
		        symbolSize: function (val) {
//		        	console.log(val);
		            return val[2] / 20;
		        },
		        itemStyle: {
		            normal: {
//		                color: '#a6c84c'
		            }
		        },
		        data: convertData2(pointdata),
		    }
		]
	};

 	main_map.setOption(option1, true);
	main_map.on('click', function (param){  
		if (param.componentType === 'series') {
			if (param.seriesIndex === 2) {
//				alert(param.name);
				localStorage.setItem("jwds",param.value);
		    	localStorage.setItem("portname",param.name);
	        	window.location.href="index_rjyy.html"; 
			} 
	 	}
    }); 
		}
	})
				}
			})
 
 
}
//七日总订舱量
var foreignBookingQuantity=function(){
	 $.ajax({
	        type: "post",
	        async: true,
	        url: "/enReport/foreignBookingQuantity",
	        data: parameter,
	        dataType: "json",
	        success: function(data){
	        	labels4=[];
	        	datas4=[];
	        	for(var i=0;i<data.length;i++){
	        		labels4.push(data[i].d);
	        		datas4.push(data[i].teu);
	        	}
		 		var ctx4 = document.getElementById('chart4').getContext('2d');
				var myChart4 = new Chart(ctx4, {
				type: 'line',
				data: {
					labels: labels4,
					datasets: [{
							label: "订舱量",
							borderWidth: '3',
							backgroundColor: "rgba(94,151,200,0.5)",
							borderColor: "rgba(94,151,200,1)",
							pointBackgroundColor: "#46ffc3",
							pointStrokeColor: "#fff",
							data: datas4
						}
					]
				},
				options: {
					legend: {
						labels: {
						 
						},
					},
					scales: {
						yAxes: [{
							stacked: false
						}]
					}
				},
			});
			setInterval(function () {
				$.ajax({
			        type: "post",
			        async: true,
			        url: "/enReport/foreignBookingQuantity",
			        data: parameter,
			        dataType: "json",
			        success: function(data){
			        	labels4=[];
	        			datas4=[];
			        	for(var i=0;i<data.length;i++){
			        		labels4.push(data[i].d);
			        		datas4.push(data[i].teu);
			        	}
			        	myChart4.data.datasets.forEach((dataset) => {
		 			  		data.labels=labels4;
		 			        dataset.data =datas4;
					    });
					}
				})
	    		myChart4.update();
		}, 3600000);
        	}
    });
}
//月份货物重量
var  foreignMonthBookingQuantity=function(){
	$.ajax({
        type: "post",
        async: true,
        url: "/enReport/foreignMonthBookingQuantity",
        data: parameter,
        dataType: "json",
        success: function(data){
        	datas22=[];
         	for(var j=0;j<data.length;j++){
         		datas22.push(data[j].teu);
         	}
         	foreignCargoWeight();
		}
	})
 
}

var foreignCargoWeight =function(){
		$.ajax({
        type: "post",
        async: true,
        url: "/enReport/foreignCargoWeight",
        data: parameter,
        dataType: "json",
        success: function(data){
        	labels2=[];
        	datas2=[];
        	for(var i=0;i<data.length;i++){
        		datas2.push(data[i].cfweight);
	     		labels2.push(data[i].mm);
        	}
        	var ctx2 = document.getElementById('chart2').getContext('2d');
			var myChart2 = new Chart(ctx2, {
				type: 'bar',
				data: {
					labels: labels2,
					datasets: [{
							label: "货物重量",
							borderWidth: '3',
							backgroundColor: "rgba(94,151,200,0.5)",
							borderColor: "rgba(94,151,200,1)",
							pointBackgroundColor: "#46ffc3",
							pointStrokeColor: "#fff",
							data: datas2,
							yAxisID: 'left-y-axis',
					},
					{
							label: "订舱量",
							borderWidth: '3',
							backgroundColor: "rgba(212,228,249,0.5)",
							borderColor: "rgba(212,228,249,1)",
							pointBackgroundColor: "#46ffc3",
							pointStrokeColor: "#fff",
							data: datas22,
							yAxisID: 'right-y-axis',
						}
					]
				},
				options: {
					scales: {
			            yAxes: [{
			                id: 'left-y-axis',
			                position: 'left',
			                ticks: {
			                    callback: function(value, index, values) {
			                        return (value/1000)+'k';
			                    }
			                }
			            },{
			                id: 'right-y-axis',
			                position: 'right'
			            }]
			        },
					legend: {
						labels: {
							//	    			defaultFontColor: '#ffffff',
							//		            fontColor: '#ffffff',
						},
						//	            display: false,
					}
				},
			});
			setInterval(function () {
					$.ajax({
				        type: "post",
				        async: true,
				        url: "/enReport/foreignCargoWeight",
				        data: parameter,
				        dataType: "json",
				        success: function(data){
				        	labels2=[];
				        	datas2=[];
				        	for(var i=0;i<data.length;i++){
				        		datas2.push(data[i].cfweight);
					     		labels2.push(data[i].mm);
				        	}
				        	$.ajax({
						        type: "post",
						        async: true,
						        url: "/enReport/foreignMonthBookingQuantity",
						        data: parameter,
						        dataType: "json",
						        success: function(data){
						        	datas22=[];
						        	for(var j=0;j<data.length;j++){
						        		datas22.push(data[j].teu);
							      
						        	}
						        	myChart2.data.datasets.forEach((dataset) => {
					 			  		data.labels=labels2;
					 			        myChart2.data.datasets[0].data =datas2;
					 			        myChart2.data.datasets[1].data =datas22;
								    });
								}
							})
						}
					})
			    myChart2.update();
			}, 3600000);
			
		}
	})
}
//航线贡献值
var routeContribution =function(){
	$.ajax({
        type: "post",
        async: true,
        url: "/enReport/routeContribution",
        data: parameter,
        dataType: "json",
        success: function(data){
        	labels6=[];
        	datas6=[];
        	for(var i=0;i<data.length;i++){
        		labels6.push(data[i].service_name);
        		datas6.push(data[i].teu);
        	}
	       	var ctx6 = document.getElementById('chart6').getContext('2d');	
			var myChart6 = new Chart(ctx6, {
				type: 'bar',
//				axisLabel: {  
//				   interval:0,  
//				   rotate:40  
//				},
				data: {
					labels: labels6,
					datasets: [{
						label: "数据一",
						borderWidth: '3',
						backgroundColor: "rgba(94,151,200,0.5)",
						borderColor: "rgba(94,151,200,1)",
						pointBackgroundColor: "#46ffc3",
						pointStrokeColor: "#fff",
						data: datas6
					}]
				},
				options: {
					 onClick: function(e){
					    var element = this.getElementAtEvent(e);
					    if(element.length > 0){
//					            alert(element[0]._index);
					            var labelindex=element[0]._index
					            var route_name=window.btoa(encodeURIComponent(labels6[labelindex]));
					            
//					            routepage(route_name);
					            window.open("routepage.html?route="+route_name);
					      }
					    },  
					scales: {
				        xAxes: [{
				            ticks: {
				            	autoSkip: false,
				            }
				        }]
				    },
					maintainAspectRatio: false,
					legend: {
						labels: {
							
						},
						display: false,
					},
				},
			});
			setInterval(function () {
					$.ajax({
				        type: "post",
				        async: true,
				        url: "/enReport/routeContribution",
				        data: parameter,
				        dataType: "json",
				        success: function(data){
				        	labels6=[];
				        	datas6=[];
				        	for(var i=0;i<data.length;i++){
				        		labels6.push(data[i].service_name);
				        		datas6.push(data[i].teu);
				        	}
						}
					})
			  	myChart6.data.datasets.forEach((dataset) => {
			  		data.labels=labels6;
			        dataset.data =datas6;
			    });
			    myChart6.update();
			}, 3600000);
    	}
    });
}
//吞吐量港口排名
var throughputPortRanking =function(){
	$.ajax({
	        type: "post",
	        async: true,
	        url: "/enReport/throughputPortRanking",
//	        data: parameter,
	        dataType: "json",
	        success: function(data){
	        	labels1=[];
	        	datas=[];
	        	for(var i=0;i<data.length;i++){
	        		if(i<5){
	        			labels1.push(data[i].current_port)
	        			datas.push(data[i].teu);
	        		}
	        	}
		    	var ctx3 = document.getElementById('chart3').getContext('2d');
				var myChart3 = new Chart(ctx3, {
					type: 'horizontalBar',
					data: {
						labels:labels1,
						datasets: [{
							label: "港口吞吐量",
							borderWidth: '2',
							backgroundColor: [
								"rgba(212,228,249,0.5)",
								"rgba(25,198,198,0.5)",
								"rgba(202,127,50,0.5)",
								"rgba(94,151,200,0.5)",
								"rgba(206,120,222,0.5)",
								"rgba(94,151,200,0.5)"
							],
							borderColor: [
								"rgba(212,228,249,1)",
								"rgba(25,198,198,1)",
								"rgba(202,127,50,1)",
								"rgba(94,151,200,1)",
								"rgba(206,120,222,1)",
								"rgba(94,151,200,1)"
							],
							pointBackgroundColor: "#46ffc3",
							pointStrokeColor: "#fff",
							data: datas
						}]
					},
					options: {
						maintainAspectRatio: false,
						legend: {
							labels: {
								//	    			defaultFontColor: '#ffffff',
								//		            fontColor: '#ffffff',
							},
							display: false,
						},
					},
				});
			 	setInterval(function () {
					$.ajax({
				        type: "post",
				        async: true,
				        url: "/enReport/throughputRanking",
				        data: parameter,
				        dataType: "json",
				        success: function(data){
				        	labels1=[];
	        				datas=[];
						   	for(var i=0;i<5;i++){
				        		labels1.push(data[i].port)
				        		datas.push(data[i].teu);
				        	}
						}
					})
			  	myChart3.data.datasets.forEach((dataset) => {
			  		data.labels=labels1;
			        dataset.data =datas;
			    });
			    myChart3.update();
			}, 3600000);
        	}
    });
}
 
//货物比重(办事处)
var goodsOrgSpecificWeight =function(){
	    $.ajax({
	        type: "post",
	        async: true,
	        url: "/enReport/boxRatio",
	        data: parameter,
	        dataType: "json",
	        success: function(data){
	        	var ctx7=[];
			    ctx7_labels1=[];
			    ctx7_data1=[];
			    total1=0;
   				four1=0;
   				var GP20=0;
   				var HQ40=0;
   				var RH40=0;
   				var RH20=0;
			     for(var i=0; i<data.length;i++){
			     	if(data[i].boxtype=="20GP" && GP20 ==0){
			     		ctx7.push({
			     			"boxtype":"20GP",
			     			"bp":data[i].bp
			     		});
			     		GP20++;
			     	}
			     	if(data[i].boxtype=="40HQ" && HQ40 ==0){
			     		ctx7.push({
			     			"boxtype":"40HQ",
			     			"bp":data[i].bp
			     		});
			     		HQ40++;
			     	}
			     	if(data[i].boxtype=="40RH" && RH40 ==0){
			     		ctx7.push({
			     			"boxtype":"40RH",
			     			"bp":data[i].bp
			     		});
			     		RH40++;
			     	}
			     	if(data[i].boxtype=="20RH" && RH20 ==0){
			     		ctx7.push({
			     			"boxtype":"20RH",
			     			"bp":data[i].bp
			     		});
			     		RH20++;
			     	}
//			     	if(i<4){
//			     		ctx7_labels1.push(data[i].fname_l2);
//		     			ctx7_data1.push(data[i].qty);
//		     			four1+=data[i].qty;
//			     	}
//			     	total1+=data[i].qty;
			     }
			     for(var j=0;j<ctx7.length;j++){
			     	ctx7_labels1.push(ctx7[j].boxtype);
 	     			ctx7_data1.push(ctx7[j].bp);
			     }
//			     ctx7_labels1.push("其他");
//				 ctx7_data1.push(total1-four1);
			    var ctx8 = document.getElementById('chart8').getContext('2d');
				var myChart8 = new Chart(ctx8, {
					type: 'pie',
					data: {
						labels: ctx7_labels1,
						datasets: [{
							data: ctx7_data1,
							backgroundColor: [
								"rgba(94,151,200,0.5)",
								"rgba(212,228,249,0.5)",
								"rgba(25,198,198,0.5)",
								"rgba(202,127,50,0.5)",
								"rgba(206,120,222,0.5)",
							],
							borderColor: [
								"rgba(94,151,200,1)",
								"rgba(212,228,249,1)",
								"rgba(25,198,198,1)",
								"rgba(202,127,50,1)",
								"rgba(206,120,222,1)",
							],
							borderWidth: '2',
							pointRadius: '10',
							hoverBorderWidth: '0',
							hoverBorderColor: ['#2185da', '#2185da', '#2185da'],
						}],
					},
					options: {
						legend: {
							display: true,
						},
					},
				});
					setInterval(function () {
						$.ajax({
					        type: "post",
					        async: true,
					        url: "/enReport/boxRatio",
					        data: parameter,
					        dataType: "json",
					        success: function(data){
							 		        	var ctx7=[];
			    ctx7_labels1=[];
			    ctx7_data1=[];
			    total1=0;
   				four1=0;
   				var GP20=0;
   				var HQ40=0;
   				var RH40=0;
   				var RH20=0;
			     for(var i=0; i<data.length;i++){
			     	if(data[i].boxtype=="20GP" && GP20 ==0){
			     		ctx7.push({
			     			"boxtype":"20GP",
			     			"bp":data[i].bp
			     		});
			     		GP20++;
			     	}
			     	if(data[i].boxtype=="40HQ" && HQ40 ==0){
			     		ctx7.push({
			     			"boxtype":"40HQ",
			     			"bp":data[i].bp
			     		});
			     		HQ40++;
			     	}
			     	if(data[i].boxtype=="40RH" && RH40 ==0){
			     		ctx7.push({
			     			"boxtype":"40RH",
			     			"bp":data[i].bp
			     		});
			     		RH40++;
			     	}
			     	if(data[i].boxtype=="20RH" && RH20 ==0){
			     		ctx7.push({
			     			"boxtype":"20RH",
			     			"bp":data[i].bp
			     		});
			     		RH20++;
			     	}
//			     	if(i<4){
//			     		ctx7_labels1.push(data[i].fname_l2);
//		     			ctx7_data1.push(data[i].qty);
//		     			four1+=data[i].qty;
//			     	}
//			     	total1+=data[i].qty;
			     }
			     for(var j=0;j<ctx7.length;j++){
			     	ctx7_labels1.push(ctx7[j].boxtype);
 	     			ctx7_data1.push(ctx7[j].bp);
			     }
							}
						})
				  	myChart8.data.datasets.forEach((dataset) => {
				  		data.labels=ctx7_labels1;
				        dataset.data =ctx7_data1;
				    });
				    myChart8.update();
				}, 3600000);
        	}
    });
}
//货物比重(全国)
var goodsCNSpecificWeight =function(){
	    $.ajax({
	        type: "post",
	        async: true,
	        url: "/enReport/goodsCNSpecificWeight",
	        data: parameter,
	        dataType: "json",
	        success: function(data){
			    ctx7_labels=[];
			    ctx7_data=[];
			    total=0;
			    four=0;
			     for(var i=0; i<data.length;i++){
			     	if(i<4){
			     		ctx7_labels.push(data[i].goodsname);
			     		ctx7_data.push(data[i].qty);
			     		four+=data[i].qty;
			     	}
			     	 total+=data[i].qty;
			     }
			     ctx7_labels.push("其他");
			    ctx7_data.push(total-four);
			    var ctx7 = document.getElementById('chart7').getContext('2d');
				var myChart7 = new Chart(ctx7, {
					type: 'pie',
					data: {
						labels: ctx7_labels,
						datasets: [{
							data: ctx7_data,
							backgroundColor: [
								"rgba(94,151,200,0.5)",
								"rgba(25,198,198,0.5)",
								"rgba(202,127,50,0.5)",
								"rgba(206,120,222,0.5)",
								"rgba(212,228,249,0.5)",
							],
							borderColor: [
								"rgba(94,151,200,1)",
								"rgba(25,198,198,1)",
								"rgba(202,127,50,1)",
								"rgba(206,120,222,1)",
								"rgba(212,228,249,1)",
							],
							borderWidth: '2',
							pointRadius: '10',
							hoverBorderWidth: '0',
							hoverBorderColor: ['#2185da', '#2185da', '#2185da'],
						}],
					},
					options: {
						onClick: function(e){
					    	var element = this.getElementAtEvent(e);
					    	if(element.length > 0){
//					            alert(element[0]._index);
					            var labelindex=element[0]._index
					            var cargo_name=window.btoa(encodeURIComponent(ctx7_labels[labelindex]));
//					            cargodetail(cargo_name);
					            window.open("cargopage.html?cargoname="+ cargo_name);
					     	}
					    },
						legend: {
							display: true,
							labels: {
								filter: function(legenditem,data){
									if(legenditem.text!="其他"){
										return true;
									}
								}
							}
						},
					},
				});
					setInterval(function () {
						$.ajax({
					        type: "post",
					        async: true,
					        url: "/enReport/goodsCNSpecificWeight",
					        data: parameter,
					        dataType: "json",
					        success: function(data){
							    ctx7_labels=[];
							    ctx7_data=[];
							    total=0;
				   				four=0;
							     for(var i=0; i<data.length;i++){
							     	if(i<4){
							     		ctx7_labels.push(data[i].goodsname);
							     		ctx7_data.push(data[i].qty);
							     		four+=data[i].qty;
							     	}
							     	 total+=data[i].qty;
							     }
							     ctx7_labels.push("其他");
							    ctx7_data.push(total-four);
							}
						})
				  	myChart7.data.datasets.forEach((dataset) => {
				  		data.labels=ctx7_labels;
				        dataset.data =ctx7_data;
				    });
				    myChart7.update();
				}, 3600000);
        	}
    });
}
//外贸总订舱量
var foreignBookingQuantityAll=function(){
	 $.ajax({
	        type: "post",
	        async: true,
	        url: "/enReport/foreignBookingQuantityAll",
	        data: parameter,
	        dataType: "json",
	        success: function(data){
			var counter=$('.counter1').jOdometer({
				increment: 1,
				counterStart:"0000000"+teus, 
				easing:'linear',
				numbersImage: 'images/jodometer-numbers.png', 
			  	spaceNumbers: 1, 
			  	heightNumber: 64,
			  	widthNumber:32,
			  	spaceNumbers:10,
			  	formatNumber:true,
			});
		  counter.goToNumber(data[0].teu);
		  teus =data[0].teu;
		  setTimeout("foreignBookingQuantityAll()", 60000);
        	}
    });
}
//客户订舱量前十名
var customerTopTen =function(){
	$.ajax({
	        type: "post",
	        async: true,
	        url: "/enReport/customerTopTen",
	        data: parameter,
	        dataType: "json",
	        success: function(data){
		      var str="";
		      for(var i=0;i<data.length;i++){
		      	str+='<li>'+
						'<p class="status">'+(i+1)+'</p>'+
						'<p class="amount">'+data[i].cusname+'</p>'+
						'<p class="time">'+data[i].teu+'</p>'+
					'</li>'
		      }
		      $("#ul_1").html(str);
		      $("#ul_1 li").on("click",function(){
//		    	  var customername= $(this).children(".amount").html();
//		    	  customerdetail(customername);
					var customername=window.btoa(encodeURIComponent($(this).children(".amount").html()));
					window.open("customerpage.html?customer="+customername);
		      });
        	}
    });
}


$.ajax({
	type: "post",
    async: true,
    url: "/enReport/portNumber",
    data: parameter,
    dataType: "json",
    success: function(data){
//  	console.log(data);
		$('#count1').html(data[0].nums);
    }
});
$.ajax({
	type: "post",
    async: true,
    url: "/enReport/serviceNumber",
    data: parameter,
    dataType: "json",
    success: function(data){
//  	console.log(data);
    	$('#count2').html(data[0].nums);
    }
});
$.ajax({
	type: "post",
    async: true,
    url: "/enReport/vesselNumber",
    data: parameter,
    dataType: "json",
    success: function(data){
//  	console.log(data);
    	$('#count3').html(data[0].nums);
    }
});